package com.ycsj.goldmedalnewconcept.parent.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.ycsj.common.base.BaseLazyFragment;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.activity.LiveListActivity;
import com.ycsj.goldmedalnewconcept.common.adapter.HomeGvAdapter;
import com.ycsj.goldmedalnewconcept.common.bean.HomeInfo;
import com.ycsj.goldmedalnewconcept.parent.activity.ParentEventActivity;
import com.ycsj.goldmedalnewconcept.parent.activity.ParentsEvaluateTeacherActivity;
import com.ycsj.goldmedalnewconcept.parent.activity.ParentsLeaveListActivity;
import com.ycsj.goldmedalnewconcept.parent.activity.ParentsRedPackageListActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 家长端助手Fragment
 * Created by Administrator on 2019/2/19 0019.
 */

public class ParentHelpFragment extends BaseLazyFragment implements AdapterView.OnItemClickListener {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.gv)
    GridView mGv;

    //首页的展示的条目的数据集合
    private List<HomeInfo> homeInfos;

    //适配器对象
    private HomeGvAdapter adapter;

    //首页的栏目名称
//    private String[] itemNames = {"在线请假", "评价老师", "我的红包", "我的活动", "小小金", "收听直播", "邀请好友"};
//    private String[] itemNames = {"在线请假", "评价老师", "我的红包", "我的活动", "收听直播", "邀请好友"};
    private String[] itemNames = {"在线请假", "评价老师", "我的红包", "我的活动", "收听直播"};

    //首页的栏目的所有图片
//    private int[] itemResId = {R.drawable.parent_zxqj, R.drawable.parent_pjls, R.drawable.parent_wdhb, R.drawable.parent_wdhd, R.drawable.parent_xxj, R.drawable.parent_stzb, R.drawable.parent_yqhy};
    private int[] itemResId = {R.drawable.parent_zxqj, R.drawable.parent_pjls, R.drawable.parent_wdhb, R.drawable.parent_wdhd, R.drawable.parent_stzb};

    public static final String TAG = ParentHelpFragment.class.getName();

    //单体模式
    private static class LazyHolder {
        private static final ParentHelpFragment INSTANCE = new ParentHelpFragment();
    }

    public static final ParentHelpFragment newInstance() {
        return LazyHolder.INSTANCE;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_parent_help;
    }

    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);
        //初始化标题栏
        initTitle();

        //初始化数据
        initData();

        //初始化列表
        initGv();
    }

    /**
     * 初始化标题栏
     */
    private void initTitle() {
        ivBack.setVisibility(View.INVISIBLE);
        tvTitle.setText("助 手");
    }

    /**
     * 初始化数据
     */
    private void initData() {
        homeInfos = new ArrayList<>();
        for (int i = 0; i < itemNames.length; i++) {
            HomeInfo info = new HomeInfo();
            info.resId = itemResId[i];
            info.name = itemNames[i];
            homeInfos.add(info);
        }
    }

    /**
     * 初始化列表的方法
     */
    private void initGv() {
        adapter = new HomeGvAdapter(getContext(), homeInfos, R.layout.gv_home);
        mGv.setAdapter(adapter);
        mGv.setOnItemClickListener(this);
    }


    /**
     * 条目点击事件
     *
     * @param adapterView
     * @param view
     * @param pos         点击的位置
     * @param l
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        if (isDoubleClick(view)) {
            return;
        } else {
            switch (pos) {
                case 0:
                    //在线请假
                    UiUtils.startActivity(getContext(), ParentsLeaveListActivity.class);
                    break;
                case 1:
                    //评价老师
                    UiUtils.startActivity(getContext(), ParentsEvaluateTeacherActivity.class);
                    break;
                case 2:
                    //我的红包
                    UiUtils.startActivity(getContext(), ParentsRedPackageListActivity.class);
                    break;
                case 3:
                    //我的活动
                    UiUtils.startActivity(getContext(), ParentEventActivity.class);
                    break;
//                case 4:
                //小小金
//                    XxjUtils.httpLogin(getContext(), "");
//                    break;
                case 4:
                    //收听直播
                    UiUtils.startActivity(getContext(), LiveListActivity.class);
                    break;
                case 5:
                    //邀请好友
                    ToastUtils.showShort("正在开发中...");
//                UiUtils.startActivity(getContext(), InviteFriendActivity.class);
                    break;
            }
        }
    }

}
